<template>
  <div class="list-container">
    <h1>所有标签</h1>
    <div class="list">
      <!-- 标签列表 -->
      <el-tag
          v-for="tag in filteredTags"
          :key="tag"
          type="info"
          @click.native="goToTag(tag)"
      >
        {{ tag }}
      </el-tag>
    </div>
  </div>
</template>

<script>
import { books } from "@/assets/data/booksData";
import '@/assets/css/List.css';

export default {
  name: 'TagList',
  computed: {
    filteredTags() {
      // 从 books 中提取所有不重复的标签
      const allTags = books.flatMap(book => book.tags);
      return [...new Set(allTags)];
    },
  },
  methods: {
    goToTag(tag) {
      // 使用 tag 变量来动态生成跳转路径
      this.$router.push({ path: `/tag/${tag}` });
    },
  },
};
</script>
